

<form class="layui-form" lay-filter="layuiadmin-form-ctadd" id="layuiadmin-form-ctadd" style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">客户名称</label>
    <div class="layui-input-block">
      <select name="client_id" lay-verify="required" lay-filter="client-select" id="client_id">
        <option value=""></option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">签名</label>
    <div class="layui-input-block">
      <select name="signature" lay-verify="required" id="signature">
        <option value=""></option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">模板名称</label>
    <div class="layui-input-block">
      <script type="text/html" template>
        <input type="text" name="template_name" lay-verify="required"  placeholder="模板名称" autocomplete="off" class="layui-input layui-bg-gray">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">模板编号</label>
    <div class="layui-input-block">
      <script type="text/html" template>
        <input type="text" name="template_code" lay-verify="required"  placeholder="模板编号" autocomplete="off" class="layui-input layui-bg-gray">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">模板内容</label>
    <div class="layui-input-block">
      <script type="text/html" template>
        <textarea name="content" lay-verify="required"  placeholder="模板内容" class="layui-textarea layui-bg-gray"></textarea>
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-app-ctadd-submit" value="立即提交" class="layui-btn">
    </div>
  </div>
</form>

<script>
layui.use(['index', 'form'], function(){
  var $ = layui.$
  ,form = layui.form;
  $(function () {
      //客户名称下拉框
      $.ajax({
          url:layui.setter.HOST+'clients' //模拟接口
          ,type:"GET"
          ,dataType:"json"
          ,success:function (res) {
             if(res.code == 0){
                 for(var i=0;i<res.data.length;i++){
                     if(res.data[i].status == '正常'){
                         $('#client_id').append("<option value='"+res.data[i].id+"'>"+res.data[i].name+"</option>");
                     }
                     form.render('select');
                 }
             }
          }
      });
      form.on('select(client-select)', function(data){
          //签名下拉框
          $.ajax({
              url:layui.setter.HOST+'smssigns' //模拟接口
              ,type:"GET"
              ,data:{name:data.elem.innerText.trim()}
              ,dataType:"json"
              ,success:function (res) {
                  if(res.code == 0){
                      for(var i=0;i<res.data.length;i++){
                          if(res.data[i].status == '正常'){
                              $('#signature').append("<option value='"+res.data[i].signature+"'>"+res.data[i].signature+"</option>");
                          }
                          form.render('select');
                      }
                  }
              }
          });
      });
  });
})
</script>